﻿using Dapper;
using Management.Systeam.Domaina;
using MediatR;
using MySqlX.XDevAPI.Common;
using System.Text;
using Warehouse.Api.Read.AGCation.Command;
using Warehouse.Domian.Model;
using Warehouse.ErrorCode;
using Warehouse.Infrastructrue.Implenment;

namespace Warehouse.Api.Read.AGCation.Hanlder
{
    public class GetResultCommandHanlder : IRequestHandler<GetResultCommand, ApiResult<List<ResultModel>>>
    {
        DbContext db;
        ILogger<GetResultCommandHanlder> logger;

        public GetResultCommandHanlder(DbContext db, ILogger<GetResultCommandHanlder> logger)
        {
            this.db = db;
            this.logger = logger;
        }
        /// <summary>
        /// 显示结果信息的列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ApiResult<List<ResultModel>>> Handle(GetResultCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<ResultModel>> result = new ApiResult<List<ResultModel>>();
            try
            {
                var sqlBuilder = new StringBuilder();
                sqlBuilder.Append(@"  SELECT
                                        ResultId,
                                        ResultName
                                        FROM resultmodel WHERE 0=0");
                var sql = await db.DapperConnection.QueryAsync<ResultModel>(sqlBuilder.ToString());
                result.Code = ApiEume.Success;
                result.Msg = "获取库存类型成功";
                result.Data = sql.ToList();
            }
            catch (Exception ex)
            {

            }
            return result;

        }
    }
}
